package com.mcxx.modules.miniSalvation.order.service.read;

import com.mcxx.modules.base.service.read.AreaHelper;
import com.mcxx.modules.miniSalvation.order.dao.read.ExpireFamilyDetailReadDao;
import com.mcxx.modules.miniSalvation.order.dto.ExpireFamilyDetailDTO;
import com.mcxx.modules.miniSalvation.order.entity.ExpireFamilyDetailEntity;
import com.yinhai.ta404.core.restservice.requestbean.PageParam;
import com.yinhai.ta404.core.restservice.resultbean.Page;
import com.yinhai.ta404.core.transaction.annotation.TaTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@TaTransactional(readOnly = true)
public class ExpireFamilyDetailReadService {

    @Autowired
    private ExpireFamilyDetailReadDao expireFamilyDetailReadDao;
    @Autowired
    private AreaHelper areaHelper;


    public List<ExpireFamilyDetailEntity> listAll() {
    	return expireFamilyDetailReadDao.listAll();
    }



    public ExpireFamilyDetailEntity getById(String id) {
    	return expireFamilyDetailReadDao.getById(id);
    }


    public Page<ExpireFamilyDetailDTO> listExecutionPlanDetail(String expireId, PageParam pageParam) {
        expireFamilyDetailReadDao.beginPager(pageParam);

        List<ExpireFamilyDetailDTO> list = expireFamilyDetailReadDao.listExecutionPlanDetail(expireId);
        Map<String,String> stateMapping = new HashMap<>();
        stateMapping.put("0","未执行");
        stateMapping.put("1","开始执行");
        stateMapping.put("2","执行完成");
        stateMapping.put("3","执行失败");


        if(null != list && list.size() > 0){
            for(ExpireFamilyDetailDTO record : list){
                record.setState(stateMapping.get(record.getState()));
            }
        }


        return expireFamilyDetailReadDao.endPager(list);
    }


    public int countByExpireId(String expireId) {
        return expireFamilyDetailReadDao.countByExpireId(expireId);
    }


    public List<Map<String,String>> listExpireIdAndOrderId(String[] selectedRowKeys) {
        return expireFamilyDetailReadDao.listExpireIdAndOrderId(selectedRowKeys);
    }
}
